package com.dragon.sdgp.util.defaultGenerate.strategy;

import com.dragon.sdgp.util.CommonUtil;

/**
 * @AUTHOR : Dragon_Yang
 * @File : DateTimeGenerateStrategy
 * @DESCRIPTION :
 * @DATE : 2023/3/17 17:47
 */
public class DateTimeGenerateStrategy implements GenerateStrategy{
    @Override
    public String createOne() {
        return createDatetime();
    }

    /**
     * 生成是一个日期时间格式YYYY-MM-DD HH:mm:SS
     * @return
     */
    private String createDatetime(){
        StringBuilder time = new StringBuilder();
        int month = CommonUtil.getRandom(1, 13);
        int day = -1;
        if(month == 2){
            day = CommonUtil.getRandom(1, 28);
        }else if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){
            day = CommonUtil.getRandom(1, 32);
        }else {
            day = CommonUtil.getRandom(1, 31);
        }
        time.append(CommonUtil.getRandom(1930, 2100) + "-" + (month < 10 ? "0" : "") + month + "-" + (day < 10 ? "0" : "") + day + " ");
        int hour = CommonUtil.getRandom(24);
        int m = CommonUtil.getRandom(60);
        int s = CommonUtil.getRandom(60);
        time.append((hour < 10 ? "0" : "") + hour + ":" + (m < 10 ? "0" : "") + m + ":" + (s < 10 ? "0" : "") + s);
        return time.toString();
    }
}
